<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Websocket chatting</title>
</head>
<body>
    <input id="message" type="text"><input type="submit" value="发送" onclick="send()">
    <textarea id="rcvmessage" style="width:100%; height:500px"></textarea>
</body>
<script>
    let socket=new WebSocket('ws://localhost:8080/my-websocket-endpoint');
    socket.onopen=function(){
        socket.send('Hello, from Websocket client!')
    }
    socket.onmessage=function(message){
        rcvmessage.innerHTML+=(message.data+'\n')
    }
    function send(){
        socket.send(message.value)
        message.value=''
    }
</script>
</html>